package tool;

import java.util.ArrayList;

/**
 * Created by yangxianming on 2015-06-10.
 */
public class GuessContentType {

    public static String getContentType(String fileName){
        ArrayList<String> list = new ArrayList<>();
        list.add("image/gif*gif");
        list.add("text/html*html|htm");
        list.add("image/jpeg*jpe|jpeg|jpg");
        list.add("application/x-javascript*js");
        list.add("audio/mpeg*mp3");
        list.add("application/pdf*pdf");
        list.add("application/vnd.ms-powerpoint*ppt");
        list.add("application/zip*zip");
        list.add("text/plain*txt");

        String filePostfix = fileName.substring(fileName.lastIndexOf(".") + 1);
        for (String type:list){
            if (type.substring(type.indexOf("*")+1).contains(filePostfix))
                return type.substring(0, type.indexOf("*"));
        }
        return "application/octet-stream";
    }
}
